define(function () {    
    var ec=require('echarts');
    require('echarts/chart/pie'); 
    require('echarts/chart/funnel');

    var sourcePie = ec.init(document.getElementById('resume_salary_pie'));
    var option_day = {
        tooltip : {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
            orient : 'vertical',
            x : 'left',
            data:[]
        },
        toolbox: {
            show : true,
            feature : {
                mark : {show: true},
                dataView : {show: true, readOnly: false},
                magicType : {
                    show: true, 
                    type: ['pie', 'funnel']
                },
                restore : {show: true},
                saveAsImage : {show: true}
            }
        },
        calculable : false,
        series : [
            {
                name:'期望薪资',
                type:'pie',
                selectedMode: 'single',
                radius : [0, '75%'],
                // for funnel
                x: '20%',
                width: '40%',
                funnelAlign: 'right',
                max: 1000000,
                itemStyle : {
                    normal : {
                        label : {
                            show : true,
                            position:'outer'
                        },
                        labelLine : {
                            show : true
                        }
                    },
                    emphasis : {
                        label : {
                            show : true,
                            textStyle : {
                                fontSize : '13',
                                fontWeight : 'bold'
                            }
                        }
                    }
                },
                data:[]
            }
            ]
    };

    // var ecConfig = require('echarts/config');

    function resetOption(initalData){
        option_day.legend.data = initalData.nameList;
        option_day.series[0].data = initalData.data;
 
        option_day.series[0].max = initalData.max;                

        sourcePie.setOption(option_day,true);
        sourcePie.hideLoading();
    }


    /**
     * 根据指标显示日数据
     * @param index
     */
    function show(businessName){
        var industry = $('#index_salary_industry').val();
 //       var indexType = $('#index_salary').val();
        var beginDate = $('#beginDate_salary').val();

        sourcePie.showLoading({
            text: '正在努力的读取数据中...'
        });
        $.ajax({
            url: '/dashboard/info/ajax/resumeSalary',
            type: 'post',
            async: true,
            data:{"industry": industry,"beginDate":beginDate},
            dataType: 'json',
            success: function(data, textStatus) {
                resetOption(data);
            },
            error : function() {
                sourcePie.hideLoading();
            }
        });
    }

    // var zrnumber = require('echarts/util/number');
    // var zrUtil = require('zrender/tool/util');


    //时间选择事件
    $('#beginDate_salary').datepicker(datepicker_op);

    var EC={
        echart:sourcePie,
        resize:function(){sourcePie.resize();},
        'show':show
    };

    //绑定刷新
    $("#refresh_salary_btn").click(function(){
        EC.show(businessName);
    });
    EC.show(businessName);
    return EC;
});